package api

import (
	"Walker/app/http/validator"
	"Walker/app/http/validator/api"
	"Walker/app/services"
	"Walker/app/utils/response"
	"github.com/gin-gonic/gin"
)

type Login struct {
	LoginService services.Login
}

//微信注册code换取openid

func (login *Login) Register(ctx *gin.Context)  {
	//参数验证
	var param api.RegisterRequest
	err:=validator.Verify(ctx,&param)
	if err != nil{
		response.Error(ctx,err.Error())
		return
	}
	token,err :=login.LoginService.Register(param)
	if err != nil{
		response.Error(ctx,err.Error())
		return
	}
	response.Success(ctx,"查询成功",token)
	return
}

func (login *Login) Login(ctx *gin.Context){
	//参数验证
	var param api.LoginRequest
	err:=validator.Verify(ctx,&param)
	if err != nil{
		response.Error(ctx,err.Error())
		return
	}
	//处理微信数据
	data,err :=login.LoginService.Login(param)
	if err != nil{
		response.Error(ctx,err.Error())
		return
	}
	response.Success(ctx,"查询成功",data)
	return
}
